<?php

namespace app\controller;

use plugin\admin\app\service\v1\OrderNodeService;
use support\Log;
use support\Request;
use support\exception\BusinessException;

class IndexController
{

    public function index1(Request $request)
    {
        static $readme;
        if (!$readme) {
            $readme = file_get_contents(base_path('README.md'));
        }
        return $readme;
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

    /**
     * 首页
     **/
    public function index(Request $request)
    {
    }

//    /**
//     * 首页
//     **/
//    public function index(Request $request)
//    {
//        $invitation = $request->get('invitation', '');
//        $link_id = $request->get('link_id', '');
//        return raw_view('/plugin/admin/app/view/account/login_user', ['invitation' => $invitation, 'link_id' => $link_id]);
//    }

    /**
     * 根据token获取订单
     **/
    public function getOrderByToken(Request $request)
    {
        $token = $request->input('token', '');
        if (!$token) {
            return json(['code' => 1, 'msg' => 'token无效']);
        }
        $params = compact('token');
        try {
            $result = OrderNodeService::extractApi($params);
        } catch (BusinessException $e) {
            return json(['code' => 1, 'msg' => $e->getMessage()]);
        }
        return $result;
    }

    /**
     * 支付通知
     **/
    public function payNotify(Request $request)
    {
        $data = $request->all();
        $log = Log::channel('pay_notify');
        $log->info('支付通知', $data);
        return json(['code' => 0, 'msg' => 'ok']);
    }

}
